package com.spark.gaea.security.utils;

import com.spark.gaea.base.BaseBean;
import com.spark.gaea.base.TreeVo;

import java.io.Serializable;
import java.util.Date;
import java.util.UUID;

public class VoUtil {
	public static void generateCreated(final BaseBean base) {
		base.setId(UUID.randomUUID().toString());
		base.setCreated(new Date());
		try {
			base.setCreater(SessionUtil.getUserId());
			base.setCreaterName(SessionUtil.getUser().getRealname());
		} catch (Exception e) {
			base.setCreater("0");
		}
	}

	public static void generateModified(final BaseBean base) {
		base.setModified(new Date());
		try {
			base.setModifier(SessionUtil.getUserId());
			base.setModifierName(SessionUtil.getUser().getRealname());
		} catch (Exception e) {
			base.setModifier("0");
		}
	}

	public static void generateRemoved(final BaseBean base) {
		base.setRemoved(new Date());
		try {
			base.setRemover(SessionUtil.getUserId());
			base.setRemoverName(SessionUtil.getUser().getRealname());
		} catch (Exception e) {
			base.setRemover("0");
		}
	}

	public static void generateCreated(final TreeVo base) {
		base.setId(UUID.randomUUID().toString());
		base.setCreated(new Date());
		try {
			base.setCreater(SessionUtil.getUserId());
			base.setCreaterName(SessionUtil.getUser().getRealname());
		} catch (Exception e) {
			base.setCreater("0");
		}
	}

	public static void generateModified(final TreeVo base) {
		base.setModified(new Date());
		try {
			base.setModifier(SessionUtil.getUserId());
			base.setModifierName(SessionUtil.getUser().getRealname());
		} catch (Exception e) {
			base.setModifier("0");
		}
	}

	public static void generateRemoved(final TreeVo base) {
		base.setRemoved(new Date());
		try {
			base.setRemover(SessionUtil.getUserId());
			base.setRemoverName(SessionUtil.getUser().getRealname());
		} catch (Exception e) {
			base.setRemover("0");
		}
	}

	public static Serializable getUserId() {
		try {
			return SessionUtil.getUserId();
		} catch (Exception e) {
			return "0";
		}
	}
}
